/*     */ package btsm.bean;
/*     */ 
/*     */ import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.yc.util.MyMD5Util;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class sqlUsersWork
/*     */ {
				private static Log log = LogFactory.getLog(sqlUsersWork.class);
/*  16 */   String scsql = "";
/*  17 */   String addsql = "";
/*  18 */   String mdsql = "";
/*  19 */   String delsql = "";
/*  20 */   String strDQXSFilter = "5113%";
/*  21 */   public String tablesw = "";
/*  22 */   public String wheresw = "";
/*  23 */   public String idsw = "";
/*     */    
/*  25 */   private dbConnector dbcon = null;
/*  26 */   private sysPro sPro = new sysPro();
/*     */ 	private MyMD5Util md5;
/*     */   public sqlUsersWork(String tableswa, String idswa)
/*     */   {
/*  30 */     this.tablesw = tableswa;
/*  31 */     this.idsw = idswa;
/*  32 */     this.strDQXSFilter = this.sPro.getPFilter();
					md5 = new MyMD5Util();
/*     */   }
/*     */ 
/*     */   private void dbConInit() {
/*  36 */     if (this.dbcon == null)
/*  37 */       this.dbcon = new dbConnector();
/*     */   }
/*     */ 
/*     */   public void dbConClose() {
/*  41 */     if (this.dbcon != null)
/*  42 */       this.dbcon.closeAll();
/*  43 */     this.dbcon = null;
/*     */   }
/*     */ 
/*     */   public ResultSet scmeta()
/*     */     throws Exception
/*     */   {
/*  49 */     dbConInit();
/*     */ 
/*  51 */     this.scsql = ("select * from " + this.tablesw + " limit 1");
/*  52 */     this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/*     */ 
/*  54 */     return this.dbcon.execQuery(this.scsql);
/*     */   }
/*     */ 
/*     */   public String[] meta(ResultSet rs) throws Exception
/*     */   {
/*  59 */     dbConInit();
/*     */ 
/*  61 */     ResultSetMetaData rsmd = rs.getMetaData();
/*  62 */     int columnCount = rsmd.getColumnCount();
/*  63 */     String[] cols = new String[columnCount];
/*     */ 
/*  65 */     for (int i = 0; i < columnCount; i++) {
/*  66 */       cols[i] = rsmd.getColumnLabel(i + 1);
/*     */     }
/*     */ 
/*  70 */     return cols;
/*     */   }
/*     */ 
/*     */   public String[] metatype(ResultSet rs) throws Exception
/*     */   {
/*  75 */     dbConInit();
/*     */ 
/*  77 */     ResultSetMetaData rsmd = rs.getMetaData();
/*  78 */     int columnCount = rsmd.getColumnCount();
/*     */ 
/*  80 */     String[] coltype = new String[columnCount];
/*  81 */     for (int i = 0; i < columnCount; i++) {
/*  82 */       coltype[i] = rsmd.getColumnTypeName(i + 1);
/*     */     }
/*     */ 
/*  85 */     return coltype;
/*     */   }
/*     */ 
/*     */   public int getCountPage() throws Exception
/*     */   {
/*  90 */     int count = 0;
/*  91 */     dbConInit();
/*  92 */     ResultSet rs = null;
/*  93 */     if (this.idsw.equalsIgnoreCase(""))
/*  94 */       this.scsql = ("select count(username) as count from " + this.tablesw);
/*     */     else
/*  96 */       this.scsql = ("select count(id) as count from " + this.tablesw);
/*     */     try
/*     */     {
/*  99 */       this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 100 */       rs = this.dbcon.execQuery(this.scsql);
/* 101 */       if (rs.next())
/* 102 */         count = rs.getInt(1);
/*     */     }
/*     */     catch (Exception e) {
/* 105 */       throw e;
/*     */     }
/*     */ 
/* 109 */     return count;
/*     */   }
/*     */ 
/*     */   public int getCableCountPage() throws Exception
/*     */   {
/* 114 */     int count = 0;
/* 115 */     dbConInit();
/* 116 */     ResultSet rs = null;
/* 117 */     if (this.idsw.equalsIgnoreCase(""))
/* 118 */       this.scsql = ("select count(username) as count from " + this.tablesw);
/*     */     else
/* 120 */       this.scsql = ("select count(id) as count from " + this.tablesw);
/*     */     try
/*     */     {
/* 123 */       this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 124 */       rs = this.dbcon.execQuery(this.scsql);
/* 125 */       if (rs.next())
/* 126 */         count = rs.getInt(1);
/*     */     }
/*     */     catch (Exception e) {
/* 129 */       throw e;
/*     */     }
/*     */ 
/* 133 */     return count;
/*     */   }
/*     */ 
/*     */   public ResultSet scpage(int ShowPagesw, int PageSizesw)
/*     */     throws Exception
/*     */   {
/* 139 */     dbConInit();
/* 140 */     if (this.idsw.equalsIgnoreCase(""))
/* 141 */       this.scsql = ("select * from " + this.tablesw + " order by username desc limit " + (ShowPagesw - 1) * PageSizesw + "," + PageSizesw);
/*     */     else {
/* 143 */       this.scsql = ("select * from " + this.tablesw + " order by id desc limit " + (ShowPagesw - 1) * PageSizesw + "," + PageSizesw);
/*     */     }
/* 145 */     this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 146 */     return this.dbcon.execQuery(this.scsql);
/*     */   }
/*     */ 
/*     */   public ResultSet scCablePage(int ShowPagesw, int PageSizesw)
/*     */     throws Exception
/*     */   {
/* 153 */     dbConInit();
/* 154 */     if (this.idsw.equalsIgnoreCase(""))
/* 155 */       this.scsql = ("select * from " + this.tablesw + " order by username desc limit " + (ShowPagesw - 1) * PageSizesw + "," + PageSizesw);
/*     */     else {
/* 157 */       this.scsql = ("select * from " + this.tablesw + " order by id desc limit " + (ShowPagesw - 1) * PageSizesw + "," + PageSizesw);
/*     */     }
/* 159 */     this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 160 */     return this.dbcon.execQuery(this.scsql);
/*     */   }
/*     */ 
/*     */   public boolean checkLogin(String username, String password)
/*     */   {
/* 165 */     dbConInit();
/* 166 */     boolean flag = false;
/* 167 */     String sql = "select username,passwd from users where username='" + username + "' && passwd='" + md5.getMD5ofStr(password) + "' && logindisabled='1'";
/*     */     try {
					log.info(sql);
/* 169 */       ResultSet rs = this.dbcon.execQuery(sql);
/* 170 */       if (rs.next())
/* 171 */         flag = true;
/*     */       else
/* 173 */         flag = false;
					log.info("flag = "+flag);
/*     */     }
/*     */     catch (Exception e) {
/* 176 */       e.printStackTrace();
/*     */     }
/* 178 */     return flag;
/*     */   }
/*     */ 
/*     */   public int getCountdqxsList() throws Exception
/*     */   {
/* 183 */     dbConInit();
/*     */ 
/* 185 */     int count = 0;
/* 186 */     ResultSet rs = null;
/* 187 */     this.scsql = ("select count(distcode) from districtcode where distcode like \"" + this.strDQXSFilter + "\"");
/*     */     try {
/* 189 */       this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 190 */       rs = this.dbcon.execQuery(this.scsql);
/* 191 */       if (rs.next())
/* 192 */         count = rs.getInt(1);
/*     */     }
/*     */     catch (Exception e) {
/* 195 */       throw e;
/*     */     }
/*     */ 
/* 198 */     return count;
/*     */   }
/*     */ 
/*     */   public String[] scdqxslist() throws Exception
/*     */   {
/* 203 */     dbConInit();
/*     */ 
/* 205 */     String[] list = new String[getCountdqxsList()];
/* 206 */     int i = 0;
/* 207 */     this.scsql = ("select district from districtcode where distcode like \"" + this.strDQXSFilter + "\" order by distcode;");
/* 208 */     this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/* 209 */     ResultSet rs = this.dbcon.execQuery(this.scsql);
/* 210 */     while (rs.next()) {
/* 211 */       list[i] = rs.getString(1);
/* 212 */       i++;
/*     */     }
/* 214 */     return list;
/*     */   }
/*     */ 
/*     */   public ResultSet sc() throws Exception
/*     */   {
/* 219 */     dbConInit();
/* 220 */     if (this.wheresw.equalsIgnoreCase(""))
/*     */     {
/* 222 */       this.scsql = ("select * from " + this.tablesw);
/* 223 */     } else if (this.idsw.equalsIgnoreCase(""))
/* 224 */       this.scsql = ("select * from " + this.tablesw + " where username=" + '"' + this.wheresw + '"');
/*     */     else {
/* 226 */       this.scsql = ("select * from " + this.tablesw + " where id=" + '"' + this.wheresw + '"');
/*     */     }
/* 228 */     this.scsql = new String(this.scsql.getBytes("ISO8859-1"), "UTF-8");
/*     */ 
/* 230 */     return this.dbcon.execQuery(this.scsql);
/*     */   }
/*     */ 
/*     */   public boolean add(String[] para)
/*     */   {
/* 236 */     dbConInit();
/*     */ 
/* 238 */     boolean flag = true;
/* 239 */     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
/* 240 */     String strCurDate = sdf.format(new Date());
/* 241 */     String strMeta = ""; String strValues = "";
/*     */ 
/* 243 */     String[] metaa = new String[para.length];
/*     */     try {
/* 245 */       metaa = meta(scmeta());
/*     */     } catch (Exception ex) {
/* 247 */       flag = false;
/* 248 */       ex.printStackTrace();
/*     */     }
/*     */ 
/* 251 */     for (int i = 0; i < para.length - 1; i++) {
/* 252 */       if (!metaa[i].equalsIgnoreCase("id"))
/*     */       {
/* 254 */         if (metaa[i].equalsIgnoreCase("refreshtime")) {
/* 255 */           strMeta = strMeta + metaa[i] + ", ";
/* 256 */           strValues = strValues + '"' + strCurDate + "\",";
/* 257 */         } else if ((para[i].equalsIgnoreCase("")) || (para[i].equals("null"))) {
/* 258 */           strMeta = strMeta + metaa[i] + ", ";
/* 259 */           strValues = strValues + "\"\",";
/* 260 */         } else if (metaa[i].equalsIgnoreCase("passwd")) {
/* 261 */           strMeta = strMeta + metaa[i] + ", ";
/* 262 */           strValues = strValues + "password(\"" + para[i] + "\"), ";
/*     */         } else {
/* 264 */           strMeta = strMeta + metaa[i] + ", ";
/* 265 */           strValues = strValues + '"' + para[i] + "\",";
/*     */         }
/*     */       }
/*     */     }
/* 269 */     if (metaa[(para.length - 1)].equalsIgnoreCase("refreshtime")) {
/* 270 */       strMeta = strMeta + metaa[(para.length - 1)];
/* 271 */       strValues = strValues + '"' + strCurDate + "\"";
/* 272 */     } else if ((para[(para.length - 1)].equalsIgnoreCase("")) || (para[(para.length - 1)].equals("null"))) {
/* 273 */       strMeta = strMeta + metaa[(para.length - 1)];
/* 274 */       strValues = strValues + "\"\"";
/* 275 */     } else if (metaa[(para.length - 1)].equalsIgnoreCase("passwd")) {
/* 276 */       strMeta = strMeta + metaa[(para.length - 1)];
/* 277 */       strValues = strValues + "password(\"" + para[(para.length - 1)] + "\")";
/*     */     } else {
/* 279 */       strMeta = strMeta + metaa[(para.length - 1)];
/* 280 */       strValues = strValues + '"' + para[(para.length - 1)] + "\"";
/*     */     }
/*     */ 
/* 283 */     this.addsql = ("insert into " + this.tablesw + "(" + strMeta + ") values(" + strValues + ")");
/*     */     try
/*     */     {
/* 286 */       this.addsql = new String(this.addsql.getBytes("ISO8859-1"), "UTF-8");
/* 287 */       System.out.println(this.addsql);
/* 288 */       this.dbcon.execUpdate(this.addsql);
/*     */     } catch (Exception ex) {
/* 290 */       flag = false;
/* 291 */       ex.printStackTrace();
/*     */     }
/* 293 */     return flag;
/*     */   }
/*     */ 
/*     */   public boolean md(String[] para)
/*     */   {
/* 299 */     dbConInit();
/* 300 */     boolean flag = true;
/* 301 */     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
/* 302 */     String strCurDate = sdf.format(new Date());
/*     */ 
/* 304 */     String[] metaa = new String[para.length];
/*     */     try {
/* 306 */       metaa = meta(scmeta());
/*     */     } catch (Exception ex) {
/* 308 */       flag = false;
/* 309 */       ex.printStackTrace();
/*     */     }
/*     */ 
/* 312 */     int i = 0;
/* 313 */     if (!this.idsw.equalsIgnoreCase("")) {
/* 314 */       i = 1;
/*     */     }
/*     */ 
/* 317 */     this.mdsql = ("update " + this.tablesw + " set ");
/* 318 */     for (; i < para.length; i++) {
/* 319 */       if (i < para.length - 1) {
/* 320 */         if (metaa[i].equalsIgnoreCase("refreshtime"))
/* 321 */           this.mdsql = (this.mdsql + metaa[i] + "=\"" + strCurDate + "\",");
/* 322 */         else if ((para[i].equalsIgnoreCase("")) || (para[i].equals("null")))
/* 323 */           this.mdsql = (this.mdsql + metaa[i] + "=\"\",");
/* 324 */         else if (metaa[i].equalsIgnoreCase("passwd")) {
/* 325 */           if (!para[i].equalsIgnoreCase("md5passwordnc"))
/*     */           {
/* 328 */             this.mdsql = (this.mdsql + metaa[i] + "=password(\"" + para[i] + "\"),");
/*     */           }
/*     */         } else this.mdsql = (this.mdsql + metaa[i] + "=\"" + para[i] + "\",");
/*     */ 
/*     */       }
/* 333 */       else if (metaa[i].equalsIgnoreCase("refreshtime"))
/* 334 */         this.mdsql = (this.mdsql + metaa[i] + "=\"" + strCurDate + "\" ");
/* 335 */       else if ((para[i].equalsIgnoreCase("")) || (para[i].equals("null")))
/* 336 */         this.mdsql = (this.mdsql + metaa[i] + "=\"\" ");
/* 337 */       else if (metaa[i].equalsIgnoreCase("passwd"))
/* 338 */         this.mdsql = (this.mdsql + metaa[i] + "=password(\"" + para[i] + "\")");
/*     */       else {
/* 340 */         this.mdsql = (this.mdsql + metaa[i] + "=\"" + para[i] + "\"");
/*     */       }
/*     */     }
/*     */ 
/* 344 */     this.mdsql = (this.mdsql + " where username=\"" + this.wheresw + "\";");
/*     */     try
/*     */     {
/* 347 */       this.mdsql = new String(this.mdsql.getBytes("ISO8859-1"), "UTF-8");
/* 348 */       System.out.println(this.mdsql);
/* 349 */       this.dbcon.execUpdate(this.mdsql);
/*     */     } catch (Exception ex) {
/* 351 */       flag = false;
/* 352 */       ex.printStackTrace();
/*     */     }
/* 354 */     return flag;
/*     */   }
/*     */ 
/*     */   public boolean mdUserSet(String[] para)
/*     */   {
/* 360 */     dbConInit();
/* 361 */     boolean flag = true;
/*     */ 
/* 363 */     this.mdsql = ("update " + this.tablesw + " set skin=\"" + para[1] + "\", truename =\"" + para[2] + "\", identity=\"" + para[3] + "\", telephone=\"" + para[4] + "\", address=\"" + para[5] + "\" where username=\"" + para[0] + "\";");
/*     */     try
/*     */     {
/* 366 */       this.mdsql = new String(this.mdsql.getBytes("ISO8859-1"), "UTF-8");
/* 367 */       System.out.println(this.mdsql);
/* 368 */       this.dbcon.execUpdate(this.mdsql);
/*     */     } catch (Exception ex) {
/* 370 */       flag = false;
/* 371 */       ex.printStackTrace();
/*     */     }
/* 373 */     return flag;
/*     */   }
/*     */ 
/*     */   public boolean mdPasswd(String strUsername, String strPswd)
/*     */   {
/* 379 */     dbConInit();
/* 380 */     boolean flag = true;
/*     */ 
/* 382 */     this.mdsql = ("update " + this.tablesw + " set passwd=password(\"" + strPswd + "\") where username=\"" + strUsername + "\";");
/*     */     try
/*     */     {
/* 385 */       this.mdsql = new String(this.mdsql.getBytes("ISO8859-1"), "UTF-8");
/* 386 */       System.out.println(this.mdsql);
/* 387 */       this.dbcon.execUpdate(this.mdsql);
/*     */     } catch (Exception ex) {
/* 389 */       flag = false;
/* 390 */       ex.printStackTrace();
/*     */     }
/* 392 */     return flag;
/*     */   }
/*     */ 
/*     */   public boolean del()
/*     */   {
/* 398 */     dbConInit();
/* 399 */     boolean flag = true;
/* 400 */     if (this.idsw.equalsIgnoreCase(""))
/* 401 */       this.delsql = ("delete from " + this.tablesw + " where username=" + '"' + this.wheresw + '"');
/*     */     else
/* 403 */       this.delsql = ("delete from " + this.tablesw + " where id=" + '"' + this.wheresw + '"');
/*     */     try
/*     */     {
/* 406 */       this.delsql = new String(this.delsql.getBytes("ISO8859-1"), "UTF-8");
/* 407 */       this.dbcon.execUpdate(this.delsql);
/*     */     } catch (Exception ex) {
/* 409 */       flag = false;
/* 410 */       ex.printStackTrace();
/*     */     }
/* 412 */     return flag;
/*     */   }
/*     */ }

/* Location:           E:\java\apache-tomcat-6.0.36\webapps\btsm\WEB-INF\classes\
 * Qualified Name:     btsm.bean.sqlUsersWork
 * JD-Core Version:    0.6.2
 */